package com.framework.modules.order;

import com.framework.entity.sys.SysAddress;
import com.framework.exception.util.RespResult;
import com.framework.modules.sys.controller.AbstractController;
import com.framework.page.PageUtils;
import com.framework.service.LogisticsService;
import com.framework.service.TranOrderService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author wq
 */
@RestController
@RequestMapping("new/order")
public class TranOrderController extends AbstractController {

    @Autowired
    private TranOrderService tranOrderService;

    @Autowired
    private LogisticsService logisticsService;

    /**
     * 订单列表
     * @param params
     * @return
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:order:list")
    public RespResult list(@RequestParam Map<String, Object> params) {
        params.put("deptId",getDeptId());
        params.put("goodsType",1);
        PageUtils page = tranOrderService.queryList(params);
        return RespResult.ok().put("page", page);
    }


    /**
     * 物料订单列表
     * @param params
     * @return
     */
    @RequestMapping("/goodsList")
    @RequiresPermissions("sys:order:list")
    public RespResult goodsList(@RequestParam Map<String, Object> params) {
        params.put("deptId",getDeptId());
        params.put("goodsType",2);
        PageUtils page = tranOrderService.queryList(params);
        return RespResult.ok().put("page", page);
    }


    /**
     * 处理订单
     * @param params
     * @return
     */
    @RequestMapping("/handleOrder")
    public RespResult handleOrder(@RequestBody Map<String, Object> params) {
        params.put("deptId", getUser().getDeptId());
        tranOrderService.handleOrder(params);
        return RespResult.ok();
    }

    /**
     * 删除订单
     * @param orderId
     * @return
     */
    @RequestMapping("/deleteOrder")
    public RespResult deleteOrder(@RequestParam Long orderId) {
        tranOrderService.deleteById(orderId);
        return RespResult.ok();
    }

    /**
     * 查询地址
     * @param orderId
     * @return
     */
    @RequestMapping("/queryAddress/{orderId}")
    public RespResult queryAddress(@PathVariable String orderId) {
        SysAddress address = tranOrderService.queryAddressByOrderId(orderId);
        return RespResult.ok().put("address", address);
    }

    /**
     * 查询物流信息列表
     * @return
     */
    @RequestMapping("/queryLogisticList")
    public RespResult queryLogisticList() {
        return RespResult.ok().put("list", logisticsService.queryLogisticList());
    }

    /**
     * 查询订单分配详情
     * @param orderId
     * @return
     */
    @RequestMapping("/queryNoticeDetail/{orderId}")
    public RespResult queryNoticeDetail(@PathVariable Long orderId){
        Map<String,Object> result=tranOrderService.queryNoticeDetail(orderId);
        return RespResult.ok().put("result",result);
    }





}
